package com.zwr.sheller.shop.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.LSYBusinessException;
import com.zwr.sheller.shop.service.RemarkService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author LSY
 * @Date 2022/1/14 14:13
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/remark")
@Api(tags = "商家管理用户评论接口集")
@CrossOrigin
public class RemarkController {

    RemarkService remarkService;
    @Autowired
    public RemarkController(RemarkService remarkService) {
        this.remarkService = remarkService;
    }

    @PostMapping(value = "/findGoodsRemark")
    public Map<String, Object> findGoodsRemark(Long sid) throws LSYBusinessException {
        List<Map<String, Object>> remarks = remarkService.findGoodsRemark(sid);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setField("remarks", remarks);

        return jsonResult.getMap();
    }

    @PostMapping(value = "/auditRemark")
    public Map<String, Object> auditRemark(String rid) throws LSYBusinessException {
        remarkService.auditRemark(rid);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("审核成功");

        return jsonResult.getMap();
    }

    @PostMapping(value = "/replyRemark")
    public Map<String, Object> replyRemark(String rid, String reply, Boolean isAudit) throws LSYBusinessException {
        remarkService.replyRemark(rid, reply, isAudit);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("回复成功");

        return jsonResult.getMap();
    }

    @PostMapping(value = "/deleteRemark")
    public Map<String, Object> deleteRemark(String rid) throws LSYBusinessException {
        remarkService.deleteRemark(rid);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");

        return jsonResult.getMap();
    }
}
